package com.easidea.tim.dao.customer;

import java.util.List;

import org.hibernate.Criteria;
import org.springside.core.dao.extend.HibernateEntityExtendDao;

import com.easidea.tim.entity.customer.Customer;
import com.easidea.tim.entity.customer.CustomerType;

public class CustomerTypeDao extends HibernateEntityExtendDao<CustomerType> {
	@SuppressWarnings("unchecked")
	public List<CustomerType> getAllCustomerType() {
		Criteria ca = this.createUnDeletedCriteria();
		return ca.list();
	}
	public CustomerType getCustomerTypeById(Long id) {
		CustomerType type = (CustomerType)getHibernateTemplate().get(CustomerType.class, id);
		return type;
	}
	@SuppressWarnings("unchecked")
	public boolean checkDelCustomerType(Long id) {
		String hql = "select new com.easidea.tim.entity.customer.Customer(c.id,c.name,c.bizTel1,c.bizTel2,c.contactor )"
			 + " from " + Customer.class.getName() 
			 + " as c where c.deleted = 0 and c.type.id = " +id;
		List<Customer> cs =  this.getHibernateTemplate().find(hql);	
		if(cs != null && cs.size() > 0) { 
			return false;
		}
		return true;
	}
}
